home *** CD-ROM | disk | FTP | other *** search
- global clientCookie, netPlayer, gamePort, gbuffer, ip, connect, identity, netcookie, name, name2
-
- on initnet
- if objectp(xtra("xtranet")) = 0 then
- if the machineType = 256 then
- openXLib("Xtranet.x32")
- else
- openXLib("Xtranet‚Ñ¢")
- end if
- end if
- XNetInit("XNET100-84731-01878")
- set ip to XNetIPAddress()
- set gamePort to 6001
- put "-IP address=" & ip & "-" & RETURN into field "chat"
- set connect to 0
- set identity to 0
- set clientCookie to -1
- set gbuffer to EMPTY
- startconnect()
- end
-
- on onlineloop
- if connect = 0 then
- readyconnect()
- else
- if gbuffer = VOID then
- set gbuffer to EMPTY
- end if
- set Lincoming to readdata()
- put string(Lincoming) after gbuffer
- if char length(gbuffer) of gbuffer = "|" then
- doproc()
- end if
- end if
- end
-
- on senddata n
- if clientCookie < 0 then
- exit
- end if
- XNetPeerSend(clientCookie, n & "|")
- end
-
- on readdata
- if clientCookie < 0 then
- exit
- end if
- set ret to EMPTY
- set ret to XNetPeerGet(clientCookie)
- return ret
- end
-
- on connect serverName
- if the paramCount = 0 then
- set serverName to field "ip"
- end if
- set msg to "Contacting host" && serverName & "..."
- put msg & RETURN after field "chat"
- updateStage()
- set netPlayer to 0
- set netcookie to XNetPeerCreate()
- if netcookie > 0 then
- set netError to -1
- startTimer()
- repeat while (netError <> 0) and (the timer < (7 * 60))
- set netError to XNetPeerConnect(netcookie, serverName, gamePort)
- end repeat
- if netError <> 0 then
- set msg to "Error connecting with remote player: " & XNetError(netError)
- put msg & RETURN after field "chat"
- XNetClose(netcookie)
- else
- set msg to "Establishing communications..."
- put msg & RETURN after field "chat"
- updateStage()
- set sendString to "Here she comes..."
- put "Sending: " & sendString
- XNetPeerSend(netcookie, sendString)
- set receiveString to EMPTY
- startTimer()
- repeat while (receiveString = EMPTY) and (the timer < (15 * 60))
- set receiveString to XNetPeerGet(netcookie)
- end repeat
- if not stringp(receiveString) then
- connectFail(receiveString)
- else
- if receiveString <> EMPTY then
- put "Received: " & receiveString
- put "Connection verified!"
- set netPlayer to 1
- set connect to 1
- set identity to 1
- set msg to "bye " & the text of field "name"
- XNetClose(clientCookie)
- set clientCookie to netcookie
- set name to field "name"
- if (name = " ") or (name = EMPTY) then
- set name to "<anonymous>"
- end if
- set ss to "[connection established with: " & name & "]"
- send(ss)
- puppetSound(11)
- set ss to string("set name2=" && QUOTE & string(name) & QUOTE)
- senddata(ss)
- go(1)
- if not (the commandDown) then
- closeWindow()
- end if
- else
- set msg to "Connection failed!"
- put msg & RETURN after field "chat"
- connectFail(0)
- end if
- end if
- end if
- else
- set msg to "Error connecting with remote player: " & netcookie
- put msg & RETURN after field "chat"
- connectFail()
- end if
- end
-
- on startconnect
- set msg to "Waiting for other player to connect..."
- put msg & RETURN after field "chat"
- set lineCnt to the number of lines in field "chat"
- updateStage()
- set netPlayer to 0
- set connect to 0
- set netcookie to XNetPeerCreate()
- end
-
- on readyconnect
- startTimer()
- if netcookie > 0 then
- set netError to -1
- if testconnect() then
- if the mouseDown = 1 then
- connect()
- end if
- exit
- end if
- repeat while (bgAllKeys() = []) and (the mouseDown = 0) and (netError <> 0)
- set netError to XNetPeerAccept(netcookie, gamePort)
- end repeat
- if netError <> 0 then
- else
- set receiveString to EMPTY
- startTimer()
- repeat while (receiveString = EMPTY) and (the timer < (15 * 60))
- set receiveString to XNetPeerGet(netcookie)
- end repeat
- if not stringp(receiveString) then
- connectFail(receiveString)
- end if
- if receiveString <> EMPTY then
- set connect to 1
- put "Received: " & receiveString
- set sendString to "...and there she goes."
- put "Sending: " & sendString
- XNetPeerSend(netcookie, sendString)
- put "Connection verified!"
- set netPlayer to 2
- set identity to 2
- set msg to "bye "
- set err to XNetPeerSend(clientCookie, msg)
- XNetClose(clientCookie)
- set clientCookie to netcookie
- set name to field "name"
- if (name = " ") or (name = EMPTY) then
- set name to "<anonymous>"
- end if
- set ss to "[connection established with: " & name & "]"
- send(ss)
- puppetSound(11)
- set ss to string("set name2=" && QUOTE & name & QUOTE)
- senddata(ss)
- closeWindow()
- tell the stage
- initchat()
- end tell
- else
- set msg to "Error connecting with remote player: " & netError
- put msg & RETURN after field "chat"
- connectFail("timeout waiting for response")
- end if
- end if
- else
- set msg to "Error connecting with remote player: " & netcookie
- put msg & RETURN after field "chat"
- connectFail(netcookie)
- set netcookie to -1
- end if
- end
-
- on testconnect
- return inside(point(the mouseH, the mouseV), rect(203, 41, 263, 53))
- end
-
- on waitReply cookie, secondsToWait
- set timeToWait to secondsToWait * 60
- set msg to EMPTY
- startTimer()
- repeat while (msg = EMPTY) and (the timer < timeToWait)
- set msg to XNetPeerGet(cookie)
- end repeat
- if not stringp(msg) then
- connectFail(msg)
- end if
- return msg
- end
-
- on connectFail theErr
- alert("Connection failed!" & RETURN & "Error code:" && theErr)
- set err to XNetPeerSend(clientCookie, "bye")
- XNetClose(clientCookie)
- set clientCookie to 0
- abort()
- set the text of field "msg" to " "
- set the editable of member "myname" to 1
- set the editable of member "server" to 1
- repeat with i = 1 to 48
- puppetSprite(i, 0)
- end repeat
- go(1)
- abort()
- end
-